package com.calvin.study.multithread.thread;

public class Thread07 {

	public static final int SLEEP_GAP = 5000;
	public static final int MAX_TURN = 50;

	static class SleepThread extends Thread {
		static int threadSeqNum = 1;

		public SleepThread() {
			super("sleepThread-" + threadSeqNum);
			threadSeqNum++;
		}

		public void run() {
			try {
				for (int i = 1; i < MAX_TURN; i++) {
					System.out.println(getName() + ",睡眠轮次：" + i);
					Thread.sleep(SLEEP_GAP);
				}
			} catch (Exception e) {
				System.out.println(getName() + " 发生异常被中断");
			}
			System.out.println("运行结束");
		}
	}

	public static String getCurThreadName() {
		return Thread.currentThread().getName();
	}

	public static void main(String[] args) {
		for (int i = 0; i < 5; i++) {
			Thread thread = new SleepThread();
			thread.start();
		}
		System.out.println(getCurThreadName() + " 运行结束.");
	}

}
